<?php
/**
 * php GEM Project
 * 
 * LICENSE
 * 
 * PHP System Architecture Enabling Rapid Application Deployment and Scalability
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @copyright Copyright (C) 2010 Zeletron LLC (http://zeletron.com)
 * @license http://gem.zeletron.com/license
 */

/*
 * GEM/Model/Domain/Acl.php
 * 
 * 
 * @author David Joly
 * @link http://zeletron.com
 * 
 * @category GEM
 * @package GEM_Model
 * @subpackage GEM_Model_Domain
 * 
 */
class GEM_Model_Domain_Acl extends Zend_Acl
{
	public function __construct()
	{
		/* Resources */
		$this->addResource(new Zend_Acl_Resource('user'));
		
		/* Roles */
		$this->addRole(new Zend_Acl_Role('guest'))
			->addRole(new Zend_Acl_Role('member'),'guest')
			->addRole(new Zend_Acl_Role('admin'),'member');
			
		/* Priviledges */
		$this->allow('guest','user','view')
			->allow('member','user','update',new IsSameUserAssertion());
	}


}

/**
 * Asserts that the current user is the same as the user
 * resource.
 */
class IsSameUserAssertion implements Zend_Acl_Assert_Interface
{
	/**
     * Returns true if and only if the assertion conditions are met
     *
     * @see Zend_Acl_Assert_Interface#assert()
     *
     * @param  Zend_Acl                    $acl
     * @param  Zend_Acl_Role_Interface     $role
     * @param  Zend_Acl_Resource_Interface $resource
     * @param  string                      $privilege
     * @return boolean
     */
    public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $user = null, Zend_Acl_Resource_Interface $userResource = null,$privilege = null)
    {
    	return $user === $userResource;
    }
}